import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Language } from "../../../../../extend/language/Language";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { DailyAwardItem } from "./DailyAwardItem";
import { EReward } from "../../../../../Message/Public/EReward";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { DailyItemRenderer } from "./DailyItemRenderer";
import { PageTool } from "../../../../common/global/PageTool";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { DailyInfo } from "../../../model/DailyInfo";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class DailyAwardList
    
    export  class DailyAwardList /* flash.display.Sprite */
    {
        constructor(arg1: int, arg2: int)
        {
            
            this._width = arg1;
            this._height = arg2;
            this.initUI();
            return;
        }

        public dispose(): void
        {
            if (this._rewardItem1) 
            {
                this._rewardItem1.dispose();
            }
            if (this._rewardItem2) 
            {
                this._rewardItem2.dispose();
            }
            if (this._rewardItem3) 
            {
                this._rewardItem3.dispose();
            }
            return;
        }

        public /* override */ get width(): number
        {
            return this._width;
        }

        public /* override */ get height(): number
        {
            return this._height;
        }

        protected initUI(): void
        {
            this._bg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            this._bg.setSize(this._width, this._height);
            addChild(this._bg);
            this.createDailyInfo();
            this.createRewardList();
            return;
        }

        protected createDailyInfo(): void
        {
            this._titleBg1 = ResouceConst.getScaleBitmap(ImagesConst.RbListHeader);
            this._titleBg1.x = -1;
            this._titleBg1.y = -3;
            this._titleBg1.width = this.width + 5;
            this._titleBg1.height = 33;
            addChild(this._titleBg1);
            this._titleTxt1 = new Object /* flash.text.TextField */();
            var loc1=new GTextFormat(FontUtil.lishuName, 20, 16187136);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._titleTxt1.defaultTextFormat = loc1;
            this._titleTxt1.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._titleTxt1.width = this.width;
            this._titleTxt1.height = 25;
            this._titleTxt1.text = Language.getString(20956);
            this._titleTxt1.mouseEnabled = false;
            this._titleTxt1.x = 66;
            this._titleTxt1.y = this._titleBg1.y + 4;
            this._titleTxt1.filters = [FilterConst.nameGlowFilter];
            addChild(this._titleTxt1);
            this._infoTxt = new Object /* flash.text.TextField */();
            loc1 = new GTextFormat("", 12, 65280);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._infoTxt.defaultTextFormat = loc1;
            this._infoTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._infoTxt.mouseEnabled = false;
            this._infoTxt.multiline = true;
            this._infoTxt.wordWrap = true;
            this._infoTxt.textColor = 65280;
            this._infoTxt.filters = [FilterConst.nameGlowFilter];
            this._infoTxt.width = this.width - 10;
            this._infoTxt.x = (this.width - this._infoTxt.width) / 2;
            this._infoTxt.y = this._titleBg1.y + this._titleBg1.height + 10;
            addChild(this._infoTxt);
            this._checkTips = ObjCreate.createGTextField("", 0, 145, this.width - 10, 20, this, GlobalStyle.textFormat5);
            this._checkTips.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._checkTips.htmlText = Language.getString(20976);
            this._checkTips.addEventListener(flash.events.TextEvent.LINK, this.onCheckTipsLinkHandler);
            this._checkTips.visible = false;
            return;
        }

        /* internal  */onCheckTipsLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.DailyCheckEveryDayActive));
            return;
        }

        protected createRewardList(): void
        {
            this._titleBg2 = ResouceConst.getScaleBitmap(ImagesConst.RbListHeader);
            this._titleBg2.x = -1;
            this._titleBg2.y = 165;
            this._titleBg2.width = this.width + 5;
            this._titleBg2.height = 33;
            addChild(this._titleBg2);
            this._titleTxt2 = new Object /* flash.text.TextField */();
            var loc1=new GTextFormat(FontUtil.lishuName, 20, 16187136);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._titleTxt2.defaultTextFormat = loc1;
            this._titleTxt2.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._titleTxt2.width = this.width;
            this._titleTxt2.height = 25;
            this._titleTxt2.text = "护送灵兽";
            this._titleTxt2.mouseEnabled = false;
            this._titleTxt2.x = 66;
            this._titleTxt2.y = this._titleBg2.y + 4;
            this._titleTxt2.filters = [FilterConst.nameGlowFilter];
            addChild(this._titleTxt2);
            this._rewardTxt = new Object /* flash.text.TextField */();
            loc1 = new GTextFormat("", 12, 65280);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._rewardTxt.defaultTextFormat = loc1;
            this._rewardTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._rewardTxt.mouseEnabled = false;
            this._rewardTxt.multiline = true;
            this._rewardTxt.wordWrap = true;
            this._rewardTxt.textColor = 65280;
            this._rewardTxt.filters = [FilterConst.nameGlowFilter];
            this._rewardTxt.width = this.width - 10;
            this._rewardTxt.height = 100;
            this._rewardTxt.x = (this.width - this._rewardTxt.width) / 2;
            this._rewardTxt.y = this._titleBg2.y + this._titleBg2.height + 10;
            addChild(this._rewardTxt);
            this.createRewardStar();
            this._line = GlobalClass.getBitmap(ImagesConst.SplitLine);
            this._line.x = 0;
            this._line.width = this.width;
            this._line.y = 305;
            addChild(this._line);
            this.createRwardList();
            return;
        }

        protected createRewardStar(): void
        {
            this._rewardItem1 = new DailyAwardItem(EReward._ERewardItem, 5);
            this._rewardItem1.x = 15;
            this._rewardItem1.y = 245;
            addChild(this._rewardItem1);
            this._rewardItem2 = new DailyAwardItem(EReward._ERewardExperience, 5);
            this._rewardItem2.x = 15;
            this._rewardItem2.y = 263;
            addChild(this._rewardItem2);
            this._rewardItem3 = new DailyAwardItem(EReward._ERewardCoin, 5);
            this._rewardItem3.x = 15;
            this._rewardItem3.y = 281;
            addChild(this._rewardItem3);
            return;
        }

        protected createRwardList(): void
        {
            var loc3=null;
            this._itemTxt = new Object /* flash.text.TextField */();
            this._itemTxt.textColor = 16776960;
            this._itemTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._itemTxt.filters = [FilterConst.nameGlowFilter];
            this._itemTxt.mouseEnabled = false;
            this._itemTxt.width = 100;
            this._itemTxt.text = Language.getString(20957);
            this._itemTxt.x = 15;
            this._itemTxt.y = 310;
            addChild(this._itemTxt);
            var loc1=0;
            var loc2=3;
            while (loc1 <= loc2) 
            {
                loc3 = GlobalClass.getBitmap(ImagesConst.PackItemBg);
                loc3.x = 15 + Math.floor(loc1 % 4) * 46;
                loc3.y = 332 + Math.floor(loc1 / 4) * 38;
                addChild(loc3);
                ++loc1;
            }
            this._itemList = new GTileList();
            this._itemList.rowHeight = 36;
            this._itemList.columnWidth = 36;
            this._itemList.horizontalGap = 10;
            this._itemList.verticalGap = 2;
            this._itemList.columnCount = 4;
            this._itemList.rowCount = 1;
            this._itemList.width = 175;
            this._itemList.height = 42;
            this._itemList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._itemList.verticalScrollPolicy = ScrollPolicy.OFF;
            this._itemList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._itemList.setStyle("cellRenderer", DailyItemRenderer);
            this._itemList.x = 18;
            this._itemList.y = 335;
            addChild(this._itemList);
            this._page = new PageTool([], 4);
            this._pageBar = new PageSelecter();
            this._pageBar.mode = PageSelecter.SingleMode;
            this._pageBar.x = 65;
            this._pageBar.y = 375;
            addChild(this._pageBar);
            this._pageBar.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            return;
        }

        public updateData(arg1: DailyInfo): void
        {
            this.dispose();
            this._info = arg1;
            this._infoTxt.text = arg1.des;
            this._titleTxt2.text = arg1.name;
            this._rewardTxt.text = arg1.rewardDes;
            this.updateRewardItem(arg1);
            this._page.array = arg1.items;
            this._pageBar.maxPage = this._page.pagesCount;
            this.updateDataProvider(this._page.getByPageNo(1));
            return;
        }

        protected updateRewardItem(arg1: DailyInfo): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg1.award;
            for(loc1 of loc3) 
            {
                if (loc1.type == EReward._ERewardItem) 
                {
                    this._rewardItem1.updateData(loc1.value, loc1.type, 5);
                    continue;
                }
                if (loc1.type == EReward._ERewardExperience) 
                {
                    this._rewardItem2.updateData(loc1.value, loc1.type, 5);
                    continue;
                }
                if (loc1.type != EReward._ERewardCoin) 
                {
                    continue;
                }
                this._rewardItem3.updateData(loc1.value, loc1.type, 5);
            }
            return;
        }

        protected updateDataProvider(arg1: Array<any>): void
        {
            var loc1=0;
            var loc3=null;
            if (this._dataProvider) 
            {
                this._dataProvider.removeAll();
            }
            else 
            {
                this._dataProvider = new DataProvider();
            }
            var loc2=arg1.length;
            while (loc1 < loc2) 
            {
                loc3 = arg1[loc1];
                this._dataProvider.addItem(loc3);
                ++loc1;
            }
            this._itemList.dataProvider = this._dataProvider;
            return;
        }

        public onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.updateDataProvider(this._page.getByPageNo(this._pageBar.currentPage));
            return;
        }

        public setCheckTipsVisible(arg1: Boolean): void
        {
            this._checkTips.visible = arg1;
            return;
        }

        protected /* var */_info: DailyInfo;

        protected /* var */_bg: ScaleBitmap;

        protected /* var */_titleBg1: ScaleBitmap;

        protected /* var */_titleTxt1: Object /* flash.text.TextField */;

        protected /* var */_infoTxt: Object /* flash.text.TextField */;

        protected /* var */_titleBg2: ScaleBitmap;

        protected /* var */_titleTxt2: Object /* flash.text.TextField */;

        protected /* var */_rewardTxt: Object /* flash.text.TextField */;

        protected /* var */_rewardItem1: DailyAwardItem;

        protected /* var */_rewardItem2: DailyAwardItem;

        protected /* var */_rewardItem3: DailyAwardItem;

        protected /* var */_itemTxt: Object /* flash.text.TextField */;

        protected /* var */_itemList: GTileList;

        protected /* var */_dataProvider: DataProvider;

        protected /* var */_line: Object /* flash.display.Bitmap */;

        protected /* var */_page: PageTool;

        protected /* var */_width: int;

        protected /* var */_height: int;

        protected /* var */_checkTips: GTextFiled;

        protected /* var */_pageBar: PageSelecter;
    }
